﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CourseArraging.Common; 
using CourseArraging.Frm.bbxx;

namespace CourseArraging.Frm.jygl
{
    /// <summary>
    /// 版权所有
    /// 石世特@温州医学院 sst330381@gmail.com
    /// </summary> 
    public partial class FrmTecList : FrmToolbarBase
    {
        #region 字段属性
        private static FrmTecList instance;
        private YhxxService.YhxxServiceClient yhxxdao = new YhxxService.YhxxServiceClient();
        private BasicService.BasicServiceClient otherdao = new BasicService.BasicServiceClient();

        DataTable dt = new DataTable();
        #region 时间参数
        //private string[] am_time_sec = { 
        //    "8:00","8:30","9:00","9:30","10:00","10:30","11:00","11:30","12:00"};
        //private string[] pm_time_sec = { 
        //    "12:00","12:30","13:00","13:30","14:00","14:30","15:00","15:30",
        //    "16:00","16:30","17:00","17:30","18:00"};
        //private string[] eve_time_sec = { 
        //    "18:00","18:30","19:00","19:30","20:00","20:30","21:00","21:30","22:00"};
        #endregion
        #endregion

        #region 构造器

        public static FrmTecList GetInstance()
        {
            if (instance == null || instance.IsDisposed)
            {
                instance = new FrmTecList();
                instance.MdiParent = GlobalVar.frmMain;
            }
            instance.BringToFront();
            return instance;
        }

        public FrmTecList()
        {
            InitializeComponent();
            this.dataGridView1.CellDoubleClick += new DataGridViewCellEventHandler(dataGridView1_CellDoubleClick);
            showTecContact();
        }
        #endregion

        #region 事件
        void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0) return;
            FrmTecInfo frmtecinfo = new FrmTecInfo(
                dataGridView1.Rows[e.RowIndex].Cells["教员流水"].Value.ToString());
            frmtecinfo.SearchOK+=()=>{showTecContact();};
            frmtecinfo.ShowDialog();
        }

        #endregion

        #region 抽象方法实现
        public override void tsb_new_fun()
        {
            FrmTecInfo frmtecinfo = new FrmTecInfo();
            frmtecinfo.ShowDialog();
            showTecContact();
        }

        public override void tsb_del_fun()
        {
            if (dataGridView1.SelectedRows.Count != 1)
                MessageBox.Show("请选择要删除的教师 !");
            try
            {
                yhxxdao.delTecall(dataGridView1.SelectedRows[0].Cells["教员流水"].Value.ToString());
                MessageBox.Show("删除成功 !");
            }
            catch
            {
                MessageBox.Show("删除教师出错 !");
            }
        }

        public override void tsb_refresh_fun()
        {
            showTecContact();
        }

        public override void tsb_search_fun()
        {
            FrmTecCondi frm = new FrmTecCondi(null);
            frm.SearchOK += (dt) =>
                {
                    this.dataGridView1.DataSource = dt;
                };
            frm.ShowDialog();
        }

        public override void tsb_print_fun()
        {
            dt = yhxxdao.GetTecinfo4Contact(null, null, null, null, null, null);
            FrmTecBb frmTecBb = new FrmTecBb(dt);
            frmTecBb.ShowDialog();
        }
        #endregion

        #region 方法
        //显示信息 && 刷新信息
        public void showTecContact()
        {
            this.dataGridView1.DataSource = yhxxdao.GetTecinfo4Contact(null, null, null, null, null, null);
            if (this.dataGridView1.DataSource == null) return;
            this.dataGridView1.Columns["教员流水"].Visible = false;
            //this.dataGridView1.Columns["教师信息流水"].Visible = false;
            //this.dataGridView1.Columns["课程流水"].Visible = false;
            //this.dataGridView1.Columns["年级信息流水"].Visible = false;
            //this.dataGridView1.Columns["教师安排固定开始"].Visible = false;
            //this.dataGridView1.Columns["教师安排固定结束"].Visible = false;
        }

        #endregion
    }
}
